package cn.seu.together.models;

import cn.seu.together.repository.ProjRepository;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import javax.validation.constraints.Null;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


/**
 * Created by corvo on 2/14/17.
 */
@Repository
@Transactional
public class ProjDao {

    @Autowired
    private ProjRepository projRep;

    @Autowired
    private SessionFactory _sessionFactory;

    private Session getSession() {
        return _sessionFactory.getCurrentSession();
    }

    public List<Proj> getAll() {

        List<Proj> projs = projRep.findAll();
        for (int i = 0; i < projs.size(); i++) {
            Proj proj = projs.get(i);
            proj.setTeam_cnt(proj.getTeams().size());
            proj.setInst_cnt(proj.getInterests().size());
        }

        return projs;
    }

    public Proj getById(long id) {
        Proj proj = projRep.findOne(id);
        proj.setTeam_cnt(proj.getTeams().size());
        proj.setInst_cnt(proj.getInterests().size());
        return proj;
    }
}
